package com.mystudy.springcloud.controller;

import com.mystudy.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Slf4j
public class PaymentController {
	@Autowired
	private PaymentService paymentService;

	@Value("${server.port}")
	private String serverPort;

	/**
	 * @功能: 不会出问题的方法
	 */
	@GetMapping("/payment/hystrix/ok/{id}")
	public String peymentInfo_OK(@PathVariable("id") Integer id) {
		String infoOk = paymentService.paymentInfo_OK(id);
		log.info(infoOk);
		return infoOk;
	}

	/**
	 * @功能: 可能会出问题的方法
	 */
	@GetMapping("/payment/hystrix/timeout/{id}")
	public String payment_TimeOut(@PathVariable("id") Integer id) {
		String paymentTimeOut = paymentService.payment_TimeOut(id);
		log.info(paymentTimeOut);
		return paymentTimeOut;
	}

	// ----------------------------服务熔断-----------------------------

	/**
	 * @功能: 服务熔断测试方法
	 */
	@GetMapping("/payment/circuit/{id}")
	public String paymentCircuitBreaker(@PathVariable("id") Integer id) {
		String result = paymentService.paymentCircuitBreaker(id);
		log.info(result);
		return result;
	}
}
